﻿
using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using XQ.SP.Model;

namespace XQ.SP.BllServices
{
    //部门角色配置
    public partial class SysDepaSeleRolesBLL : BaseBll
    {

        private readonly XQ.SP.DalServices.SysDepaSeleRolesDal dal = new XQ.SP.DalServices.SysDepaSeleRolesDal();
        public SysDepaSeleRolesBLL()
        { }

        #region 
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool ExistsWhere(string whereSql)
        {
            return dal.ExistsWhere(whereSql);
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long Id)
        {
            return dal.Exists(Id);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public long Add(XQ.SP.Model.SysDepaSeleRolesItem model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 批量增加数据
        /// </summary>
        public bool AddList(List<XQ.SP.Model.SysDepaSeleRolesItem> models)
        {
            int rows = dal.AddList(models);
            if (rows > 0)
                return true;
            else
                return false;
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(XQ.SP.Model.SysDepaSeleRolesItem model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 批量更新数据
        /// </summary>
        public int UpdateList(List<XQ.SP.Model.SysDepaSeleRolesItem> models)
        {
            return dal.UpdateList(models);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(long Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public XQ.SP.Model.SysDepaSeleRolesItem GetModel(long Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public XQ.SP.Model.SysDepaSeleRolesItem GetModelWhereStr(string whereSql)
        {

            return dal.GetModelWhereStr(whereSql);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere = "")
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<XQ.SP.Model.SysDepaSeleRolesItem> GetModelList(string strWhere = "")
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得新增的数据
        /// </summary>
        public List<XQ.SP.Model.SysDepaSeleRolesItem> GetModelListNew(string datetimeStr)
        {
            DataSet ds = dal.GetList(" Created>='" + datetimeStr + "' ");
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<XQ.SP.Model.SysDepaSeleRolesItem> DataTableToList(DataTable dt)
        {
            List<XQ.SP.Model.SysDepaSeleRolesItem> modelList = new List<XQ.SP.Model.SysDepaSeleRolesItem>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                XQ.SP.Model.SysDepaSeleRolesItem model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new XQ.SP.Model.SysDepaSeleRolesItem();
                    
                if (dt.Rows[n]["Id"].ToString() != "")
                {
                    model.Id = Int64.Parse(dt.Rows[n]["Id"].ToString());
                }
                if (dt.Rows[n]["RolesId"].ToString() != "")
                {
                    model.RolesId = Int64.Parse(dt.Rows[n]["RolesId"].ToString());
                }
                if (dt.Rows[n]["RolesName"].ToString() != "")
                {
                    model.RolesName = dt.Rows[n]["RolesName"].ToString();
                }
                if (dt.Rows[n]["DepaId"].ToString() != "")
                {
                    model.DepaId = Int64.Parse(dt.Rows[n]["DepaId"].ToString());
                }
                if (dt.Rows[n]["DepaName"].ToString() != "")
                {
                    model.DepaName = dt.Rows[n]["DepaName"].ToString();
                }
                if (dt.Rows[n]["ParentId"].ToString() != "")
                {
                    model.ParentId = Int64.Parse(dt.Rows[n]["ParentId"].ToString());
                }
                if (dt.Rows[n]["Name"].ToString() != "")
                {
                    model.Name = dt.Rows[n]["Name"].ToString();
                }
                if (dt.Rows[n]["Description"].ToString() != "")
                {
                    model.Description = dt.Rows[n]["Description"].ToString();
                }
                if (dt.Rows[n]["Status"].ToString() != "")
                {
                    model.Status = Int32.Parse(dt.Rows[n]["Status"].ToString());
                }
                if (dt.Rows[n]["Creator"].ToString() != "")
                {
                    model.Creator = Int64.Parse(dt.Rows[n]["Creator"].ToString());
                }
                if (dt.Rows[n]["Created"].ToString() != "")
                {
                    model.Created = System.DateTime.Parse(dt.Rows[n]["Created"].ToString());
                }
                if (dt.Rows[n]["Modifier"].ToString() != "")
                {
                    model.Modifier = Int64.Parse(dt.Rows[n]["Modifier"].ToString());
                }
                if (dt.Rows[n]["Modified"].ToString() != "")
                {
                    model.Modified = System.DateTime.Parse(dt.Rows[n]["Modified"].ToString());
                }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }



        /// <summary>
        /// Model的属性对应赋值
        /// </summary>
        public void ModelCopy(XQ.SP.Model.SysDepaSeleRolesItem modelOld, XQ.SP.Model.SysDepaSeleRolesItem modelNew)
        {
            
            modelNew.Id = modelOld.Id;
            modelNew.RolesId = modelOld.RolesId;
            modelNew.RolesName = modelOld.RolesName;
            modelNew.DepaId = modelOld.DepaId;
            modelNew.DepaName = modelOld.DepaName;
            modelNew.ParentId = modelOld.ParentId;
            modelNew.Name = modelOld.Name;
            modelNew.Description = modelOld.Description;
            modelNew.Status = modelOld.Status;
            modelNew.Creator = modelOld.Creator;
            modelNew.Created = modelOld.Created;
            modelNew.Modifier = modelOld.Modifier;
            modelNew.Modified = modelOld.Modified;
        }
        #endregion

    }
}

